import { defineStore } from 'pinia'
import { ref } from 'vue'

/**
 * 全局数据存储
 */
export const useGlobalStore = defineStore(
  'global',
  () => {
    const token = ref('')
    const setToken = (data: string) => {
      token.value = data
    }
    const clearToken = () => {
      token.value = ''
    }

    return {
      token,
      setToken,
      clearToken
    }
  },
  {
    persist: {
      key: 'global',
      pick: ['token'] // 持久化字段
    }
  }
)
